﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using System.IO;

namespace Batman.Jianbei.Forum.Core.Datas
{
    public class DbContextFactory : IDesignTimeDbContextFactory<JianbeiForumDbContext2>
    {
        public JianbeiForumDbContext2 CreateDbContext(string[] args)
        {
            IConfigurationRoot configuration = new ConfigurationBuilder()
               .SetBasePath(Directory.GetCurrentDirectory())
               .AddJsonFile("appsettings.json")
               .Build();

            var builder = new DbContextOptionsBuilder<JianbeiForumDbContext2>();
            var connectionString = configuration.GetConnectionString("Default");
            builder.UseMySql(connectionString);
            return new JianbeiForumDbContext2(builder.Options);
        }
    }

    public class JianbeiForumDbContextFactory : IDesignTimeDbContextFactory<JianbeiForumDbContext>
    {
        public JianbeiForumDbContext CreateDbContext(string[] args)
        {
            IConfigurationRoot configuration = new ConfigurationBuilder()
               .SetBasePath(Directory.GetCurrentDirectory())
               .AddJsonFile("appsettings.json")
               .Build();

            var builder = new DbContextOptionsBuilder<JianbeiForumDbContext>();
            var connectionString = configuration.GetConnectionString("Default");
            builder.UseMySql(connectionString);
            return new JianbeiForumDbContext(builder.Options);
        }
    }
}
